//
// Created by shiminli on 2023/12/30.
//

#ifndef DDOFFICE_SQLHELPER_H
#define DDOFFICE_SQLHELPER_H

#include <mysql/mysql.h>
#include <mutex>
#include <iostream>


#define MYSQL_HOST "47.94.59.114"
#define MYSQL_PORT 3306
#define MYSQL_USER "root"
#define MYSQL_PASSWD "112233"
#define MYSQL_DBNAME "dd_office"

namespace ddoffice{

    class SQLHelper {
    public:
        static SQLHelper* getInstance();

        MYSQL_RES* executeQuery(const char* query) ;

        int executeUpdate(const char* query);

        std::string getMysqlError();
        std::string getMysqlInfo();
        long getLastInsertId();

    private:
        ~SQLHelper();
        SQLHelper();

    protected:
        MYSQL* conn;
        static SQLHelper* instance;
        static std::mutex mtx; // 互斥锁

    };
}



#endif //DDOFFICE_SQLHELPER_H
